package com.example.demo.util;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.Objects;
import java.util.concurrent.TimeoutException;

/**
 * @author chensixiang chensixiang1234@gmail.com
 */
public class RabbitMQUtils {

    public static Channel getChannel() {
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost("192.168.255.133");
        factory.setUsername("admin");
        factory.setPassword("123");
        Connection conn = null;
        try {
            conn = factory.newConnection();
        } catch (IOException | TimeoutException e) {
            e.printStackTrace();
        }
        if (conn != null) {
            try {
                return conn.createChannel();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        throw new NullPointerException();
    }
}
